
precision highp float;

#define PI 3.14159265359
#define TWO_PI 6.28318530718

uniform float u_strokeWidth;
uniform vec4 u_stroke;
uniform sampler2D u_texture;

varying vec2 v_rs;
varying vec2 v_uv;
varying vec4 v_color;
varying float v_shape;
const float u_buffer=.75;
uniform vec4 u_activeColor;
// const float u_gamma = 2.0 * 1.4142 / 10.0;
const float u_gamma=.08;
// const float u_scale = 128.0;
const vec3 halo=vec3(1.);
void main(){
  #ifdef TEXCOORD_0
    vec2 pos=v_uv+gl_PointCoord / 512.*64.;
    pos.y=1.-pos.y;
    vec4 textureColor=texture2D(u_texture,pos);
    // 纹理坐标
     #ifdef PICK
            if(worldId.x == 0. &&worldId.y == 0. && worldId.z==0. && textureColor == vec4(0.)){
                    discard;
                    return;
                }
            gl_FragColor = worldId;
           
         return;
      #endif

     
        // vec4 textureColor=texture2D(u_texture,pos);
        if(v_color == vec4(0.)){
             gl_FragColor= textureColor; 
        }else {
              gl_FragColor= step(0.01, textureColor.x) * v_color;
        }
        return;
    #endif
    if(v_color.a==0.)
    discard;
    vec4 pcolor=v_color;
    float ro=v_rs.x;
    float ri=v_rs.y;
    float d=0.;
    if(ro<3.){
        gl_FragColor=pcolor;
        return;
    }
    
    // vec4 textureColor = texture2D(u_texture, gl_PointCoord);
    vec2 st=gl_PointCoord*2.-1.;
    float a=atan(st.x,st.y)+PI;
    float r=TWO_PI/v_shape;
    float ratio=1.+(1.1-smoothstep(2.8,6.,v_shape));
    float dis2center=cos(floor(.5+a/r)*r-a)*length(st)*ro*ratio;
    float alpha=smoothstep(ro,ro+.1,dis2center);
    
    if(alpha==1.){
        discard;
    }
    if(u_strokeWidth>0.){//有border
        if(dis2center>ro-u_strokeWidth){
            gl_FragColor=vec4(u_stroke.xyz,u_stroke.a*(ro-dis2center));
            return;
        }else if(dis2center>ri){
            gl_FragColor=u_stroke;
            return;
        }
    }
    
    if(dis2center>ri-u_strokeWidth){
        float factor=ri-dis2center;//填充色的百分比
        if(u_strokeWidth==0.){
            float a=pcolor.a*factor;
            gl_FragColor=vec4(pcolor.rgb,a);
        }else{
            float a=u_stroke.a*(1.-factor)+pcolor.a*factor;
            gl_FragColor=vec4(u_stroke.rgb*(1.-factor)+pcolor.rgb*factor,a);
        }
    }else{
        gl_FragColor=pcolor;
    }
    #pragma include "pick"
    
}

